package com.biz.primus.ms.product.service;


import com.biz.primus.base.vo.AliRecByUserProductReqVo;
import com.biz.primus.base.vo.AliRecRespVo;
import com.biz.primus.common.config.GetUrl;
import com.biz.primus.common.utils.AESDecode;
import com.biz.primus.common.utils.JsonUtils;
import com.biz.primus.ms.base.service.AbstractBaseService;
import org.springframework.stereotype.Service;

import static com.biz.primus.common.config.RecConfig.AccessKeyID;
import static com.biz.primus.common.config.RecConfig.AccessKeySecret;


/**
 * @author 江南
 * @date 2017/1/20
 * @reviewer
 */
@Service
public class AliProductRecServiceHelper extends AbstractBaseService {

    public AliRecRespVo findRecommendByAli(AliRecByUserProductReqVo aliRecReqVo) {
        AliRecRespVo aliRecRespVo = new AliRecRespVo();
        String params = "biz_code="+aliRecReqVo.getBizCode()+"&scn_code="+aliRecReqVo.getScnCode()+"&user_id="+aliRecReqVo.getUserId()+"&item_id="+aliRecReqVo.getItemId();
        String url = associateGetUrl(params);
        String result = AESDecode.sendGet(url, AccessKeyID, AccessKeySecret);
        return JsonUtils.json2Obj(result, AliRecRespVo.class);
    }

    private String associateGetUrl(String urlParam) {
        return String.format("%s?%s", GetUrl.GET_REC.getValue(), urlParam);
    }

}
